;******************************* ;;Do it NOW.asm ;30-10-2014 ;******************************* list p=12F629 radix dec include "p12f629.inc" errorlevel -302 ; Dont complain about BANK 1 Registers during assembly __CONFIG _MCLRE_OFF & _CP_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT ;Internal osc. ;_MCLRE_OFF - master clear must be off for gp3 to work as input pin ;**************************************************************** ; variables - names and files ;**************************************************************** temp1 equ 20h ; temp2 equ 21h ; temp3 equ 22h ; temp4 equ 23h ; del_x equ 24h ; del_y equ 25h ; loops equ 26h Random equ 27h ;**************************************************************** ;Equates ;**************************************************************** status equ 0x03 rp1 equ 0x06 rp0 equ 0x05 GPIO equ 0x05 status equ 03h option_reg equ 81h ; bits on GPIO pin7 equ 0 ;GP0 DO IT later pin6 equ 1 ;GP1 Try Again pin5 equ 2 ;GP2 DO IT NOW pin4 equ 3 ;GP3 pin3 equ 4 ;GP4 Wait 5 Minutes pin2 equ 5 ;GP5 Leave it ;bits rp0 equ 5 ;bit 5 of the status register ;**************************************************************** ;Beginning of program ;**************************************************************** org 0x00 nop nop nop nop nop SetUp bsf status, rp0 ;Bank 1 movlw b'11000000' ;Set TRIS GP0,1,2,4,5 out movwf TRISIO ; bcf status, rp0 ;bank 0 movlw 07h ;turn off Comparator ports movwf CMCON ;must be placed in bank 0 clrf GPIO ;Clear GPIO of junk goto Main ;**************************************************************** ;* delays * ;**************************************************************** ;approx 150uS delay for loops for potA and PotB _150uS movlw .67 ;69 movwf temp1 _150u nop decfsz temp1,f goto _150u retlw 00 _20mS movlw .20 movwf temp2 _20 nop decfsz temp1,f goto _20 decfsz temp2,f goto _20 retlw 00 _50mS movlw .50 movwf temp2 _50 nop decfsz temp1,f goto _50 decfsz temp2,f goto _50 retlw 00 _100mS movlw 40h movwf temp2 _100 goto $+1 goto $+1 decfsz temp1,f goto _100 decfsz temp2,f goto _100 retlw 00 _500mS movlw 0FFh movwf temp2 _500 goto $+1 goto $+1 decfsz temp1,f goto _500 decfsz temp2,f goto _500 retlw 00 _5Sec movlw .10 movwf loops call _500mS decfsz loops,1 goto $-2 retlw 00 ;**************************************************************** ;* Sub Routines * ;**************************************************************** ;display the random number Display incf Random,1 ;to produce 1 to 5 decfsz Random,1 goto $+5 bsf gpio,0 call _5Sec bcf gpio,0 goto Rand decfsz Random,1 goto $+5 bsf gpio,1 call _5Sec bcf gpio,1 call Rand decfsz Random,1 goto $+5 bsf gpio,2 call _5Sec bcf gpio,2 goto Rand decfsz Random,1 goto $+5 bsf gpio,4 call _5Sec bcf gpio,4 goto Rand bsf gpio,5 call _5Sec bcf gpio,5 ;Random Number Generator Rand incf Random,1 ;file will be 4, for 5 of the 7 instructions movlw 4 subwf Random,w btfss 03,2 ;z will be set = equal goto $-4 clrf Random goto $-6 ;loops here until finger removed ;**************************************************************** ;* Main * ;**************************************************************** Main movlw 1 movwf loops bsf gpio,0 call _500mS bcf gpio,0 bsf gpio,1 call _500mS bcf gpio,1 bsf gpio,2 call _500mS bcf gpio,2 bsf gpio,5 call _500mS bcf gpio,5 bsf gpio,4 call _500mS bcf gpio,4 decfsz loops,1 goto $-.16 movlw 5 movwf loops bsf gpio,0 call _100mS bcf gpio,0 bsf gpio,1 call _100mS bcf gpio,1 bsf gpio,2 call _100mS bcf gpio,2 bsf gpio,5 call _100mS bcf gpio,5 bsf gpio,4 call _100mS bcf gpio,4 decfsz loops,1 goto $-.16 movlw .20 movwf loops bsf gpio,0 call _20mS bcf gpio,0 bsf gpio,1 call _20mS bcf gpio,1 bsf gpio,2 call _20mS bcf gpio,2 bsf gpio,5 call _20mS bcf gpio,5 bsf gpio,4 call _20mS bcf gpio,4 decfsz loops,1 goto $-.16 movlw .10 movwf loops bsf gpio,0 call _50mS bcf gpio,0 bsf gpio,1 call _50mS bcf gpio,1 bsf gpio,2 call _50mS bcf gpio,2 bsf gpio,5 call _50mS bcf gpio,5 bsf gpio,4 call _50mS bcf gpio,4 decfsz loops,1 goto $-.16 movlw 5 movwf loops bsf gpio,0 call _100mS bcf gpio,0 bsf gpio,1 call _100mS bcf gpio,1 bsf gpio,2 call _100mS bcf gpio,2 bsf gpio,5 call _100mS bcf gpio,5 bsf gpio,4 call _100mS bcf gpio,4 decfsz loops,1 goto $-.16 movlw 1 movwf loops bsf gpio,0 call _500mS bcf gpio,0 bsf gpio,1 call _500mS bcf gpio,1 bsf gpio,2 call _500mS bcf gpio,2 bsf gpio,5 call _500mS bcf gpio,5 bsf gpio,4 call _500mS bcf gpio,4 decfsz loops,1 goto $-.16 goto Display END